import time
import cv2

def read_cam():
    url = 'rtsp://192.168.1.64:554/H264?W=1280&H=720&BR=2000000&FPS=30'
    cap = cv2.VideoCapture(url)
    if cap.isOpened():
        fps = 10.0
        tic = time.time()
        while True:
            ret_val, frame = cap.read()
            #cv2.imshow('H264 Test', frame)
            cv2.waitKey(10)

            toc = time.time()
            curr_fps = 1.0 / (toc - tic)
            # calculate an exponentially decaying average of fps number
            fps = (fps*0.95 + curr_fps*0.05)
            tic = toc
            print (f'{frame.shape} FPS {fps}')
    else:
        print ("rtsp open failed")


if __name__ == '__main__':
    read_cam()
